home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Hyper / Q-R / ReWrap.cpt / Text Rewrap / card_2976.txt < prev    next >
Encoding:
Text File  |  1989-12-07  |  5.5 KB  |  224 lines

  1. -- card: 2976 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2709
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 00
  10. -- high flags: 0007
  11. -- rect: left=18 top=31 right=179 bottom=395
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 4
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: Strung Text
  20.  
  21.  
  22. -- part 2 (field)
  23. -- low flags: 00
  24. -- high flags: 0007
  25. -- rect: left=18 top=185 right=333 bottom=395
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 0 / 0
  28. -- text alignment: 0
  29. -- font id: 4
  30. -- text size: 12
  31. -- style flags: 0
  32. -- line height: 16
  33. -- part name: Unstrung Text
  34.  
  35.  
  36. -- part 3 (button)
  37. -- low flags: 00
  38. -- high flags: A003
  39. -- rect: left=413 top=101 right=123 bottom=494
  40. -- title width / last selected line: 0
  41. -- icon id / first selected line: 0 / 0
  42. -- text alignment: 1
  43. -- font id: 0
  44. -- text size: 12
  45. -- style flags: 0
  46. -- line height: 16
  47. -- part name: ReWrap
  48. ----- HyperTalk script -----
  49. on mouseUp
  50.   ask "Line size:" with "40"
  51.   if it is empty then exit mouseUp
  52.   put it into lineLength
  53.   lock screen
  54.   set cursor to 4
  55.   put reWrap(cd field "Strung Text", lineLength) into cd field "Unstrung Text"
  56.   unlock screen
  57.   set cursor to 1
  58. end mouseUp
  59.  
  60. function reWrap textIn, lineLength
  61. --
  62. --  Set starting values ...
  63. --
  64. put 1 into startChar
  65. put the length of textIn into numChars
  66. if numChars < lineLength then
  67.   put numChars into lineLength
  68. end if
  69. put lineLength into endChar
  70. put empty into textOut
  71. put 1 into showLine
  72. --
  73. --  The main processing loop ...
  74. --
  75. repeat
  76.   put "Working on line" && showLine && "of the reWrapped text ..." into msg
  77.   put char startChar to endChar of textIn into testString
  78.   --
  79.   --  Respect existing Returns in the text ...
  80.   --
  81.   put offset(return,testString) into returnLoc
  82.   if returnLoc ‚↠0 then
  83.     put (startChar + (returnLoc - 1)) into endChar
  84.   else
  85.     if endChar ‚↠numChars then
  86.       --
  87.       --  Back up till we find a space
  88.       --
  89.       repeat until char endChar of textIn = " "
  90.         subtract 1 from endChar
  91.         --
  92.         --  Let's make sure we don't box ourselves in ...
  93.         --
  94.         if endChar ‚â§ startChar then
  95.           put ((startChar + the number of chars in testString) - 1) into endChar
  96.           exit repeat
  97.         end if
  98.       end repeat
  99.     end if
  100.   end if
  101.   put char startChar to endChar of textIn after textOut
  102.   add 1 to showLine
  103.   if endChar = numChars then
  104.     exit repeat
  105.   end if
  106.   --
  107.   --  We don't need to add a Return if we've already got one
  108.   --
  109.   if returnLoc = 0 then
  110.     put return after textOut
  111.   end if
  112.   --
  113.   --  Increment Start and End positions for the next go-round
  114.   --
  115.   put (endChar + 1) into startChar
  116.   if (numChars - endChar) < lineLength then
  117.     put numChars into endChar
  118.   else
  119.     add lineLength to endChar
  120.   end if
  121. end repeat
  122. hide msg
  123. return textOut
  124. end reWrap
  125.  
  126.  
  127. -- part 4 (field)
  128. -- low flags: 81
  129. -- high flags: 2002
  130. -- rect: left=18 top=31 right=332 bottom=395
  131. -- title width / last selected line: 0
  132. -- icon id / first selected line: 0 / 0
  133. -- text alignment: 0
  134. -- font id: 3
  135. -- text size: 12
  136. -- style flags: 0
  137. -- line height: 16
  138. -- part name: Notes
  139.  
  140.  
  141. -- part 5 (button)
  142. -- low flags: 00
  143. -- high flags: A000
  144. -- rect: left=430 top=42 right=91 bottom=478
  145. -- title width / last selected line: 0
  146. -- icon id / first selected line: 2478 / 2478
  147. -- text alignment: 1
  148. -- font id: 0
  149. -- text size: 12
  150. -- style flags: 0
  151. -- line height: 16
  152. -- part name: Notes
  153. ----- HyperTalk script -----
  154. on mouseUp
  155.   if the short name of me is "Notes" then
  156.     show cd field "Notes"
  157.     set the name of me to "Hide"
  158.   else
  159.     hide cd field "Notes"
  160.     set the name of me to "Notes"
  161.   end if
  162. end mouseUp
  163.  
  164.  
  165.  
  166. -- part contents for card part 1
  167. ----- text -----
  168. Poor soul, the centre of our sinful earth; thrall to these rebel powers that thee array; why dost thou pine within and suffer dearth, painting thy outward walls so costly gay?  Why so large cost, having so short a lease, dost thou upon thy fading mansion spend?
  169.  
  170. Shall worms, inheritors of this excess, eat up thy charge?  Is this thy body's end?
  171.  
  172. Then, soul, live thou upon thy servant's loss, and let that pine to aggravate thy store.  Buy terms divine in selling hours of dross.  Within be fed; without be rich no more.
  173.  
  174. So shalt thou feed on death, that feeds on men; and death once dead, there's no more dying then.
  175.  
  176. -- part contents for card part 4
  177. ----- text -----
  178. ReWrap illustrates a function that takes a text field and adjusts the word wrap to a specified line length.  It puts in Return characters as needed to maintain the line length.
  179.  
  180. The parameters are the text field you want to rewrap and the length you want to adjust it to.
  181.  
  182. The result is in It.
  183.  
  184. Mainly a HyperTalk experiment; the speed of the operation leaves something to be desired.
  185.  
  186. -- Tad Davis, CompuServe ID 72320,3220
  187.                       GEnie ID TAD.DAVIS
  188.  
  189. The text, by the way, is Sonnet 146 by William Shakespeare.
  190.  
  191. -- part contents for card part 2
  192. ----- text -----
  193. Poor soul, the centre of 
  194. our sinful earth; thrall 
  195. to these rebel powers 
  196. that thee array; why 
  197. dost thou pine within 
  198. and suffer dearth, 
  199. painting thy outward 
  200. walls so costly gay?  
  201. Why so large cost, 
  202. having so short a lease, 
  203. dost thou upon thy 
  204. fading mansion spend?
  205.  
  206. Shall worms, inheritors 
  207. of this excess, eat up 
  208. thy charge?  Is this thy 
  209. body's end?
  210.  
  211. Then, soul, live thou 
  212. upon thy servant's loss, 
  213. and let that pine to 
  214. aggravate thy store.  
  215. Buy terms divine in 
  216. selling hours of dross.  
  217. Within be fed; without 
  218. be rich no more.
  219.  
  220. So shalt thou feed on 
  221. death, that feeds on 
  222. men; and death once 
  223. dead, there's no more 
  224. dying then.